﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataSet QueryGSMATK(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            // GSCMANDANT GSCART GSCVAR GSCFARBE


            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GSMATK WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM GSMATK WHERE  "
                    + "  GSMMANDANT=:GSMMANDANT AND GSMART=:GSMART AND GSMVAR=:GSMVAR";
                    or1.Parameters.Add("GSMMANDANT", OracleType.NVarChar).Value = dwData["GSMMANDANT"].ToString();
                    or1.Parameters.Add("GSMART", OracleType.NVarChar).Value = dwData["GSMART"].ToString();
                    or1.Parameters.Add("GSMVAR", OracleType.NVarChar).Value = dwData["GSMVAR"].ToString();
                    break;
                case 4:
                    or1.CommandText = "  SELECT DISTINCT GS.* FROM GAAUF GA RIGHT JOIN GSMATK GS ON GAMANDANT=GSMMANDANT"
                        + " AND GAART=GSMART "
                        + "  WHERE GAMANDANT=:GAMANDANT AND  GAAUFKRS=:GAAUFKRS AND GAAUFLFD=:GAAUFLFD ";
                    or1.Parameters.Add("GAMANDANT", OracleType.NVarChar).Value = dwData["GAMANDANT"].ToString();
                    or1.Parameters.Add("GAAUFKRS", OracleType.NVarChar).Value = dwData["GAAUFKRS"].ToString();
                    or1.Parameters.Add("GAAUFLFD", OracleType.NVarChar).Value = dwData["GAAUFLFD"].ToString();
                    break;
                case 2:
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "GSMATK";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
